<?php
/***************************************************************************
 * 
 * Copyright (c) 2010 , Inc. All Rights Reserved
 * $Id$:TestFuncs.php,2010/05/26 14:02:37 
 * 
 **************************************************************************/
 
 
 
/**
 * @file TestFuncs.php
 * @author huqingping(huqingping@)
 * @date 2010/05/26 14:02:37
 * @version 1.0 
 * @brief 
 *  
 **/


final class TestFuncs extends TestCase
{

	function testAccessable()
	{
		$ret = $this->fetch('/HapN2/mypage',array('get'=>array('_of'=>'json')));	
		$json = $ret->json();
		$this->assertEquals('hapn.ok',$json['err']);
		$ret = $this->fetch('/HapN2/notaccess',array('get'=>array('_of'=>'json')));	
		$json = $ret->json();
		$this->assertEquals('hapn.u_notfound',$json['err']);
	}


	function testProtecedPage()
	{
		$ret = $this->fetch('/HapN/index',array('get'=>array('_of'=>'json')));	
		$json = $ret->json();
		$this->assertEquals('hapn.u_notfound',$json['err']);
		$ret = $this->fetch('/HapN/_before',array('get'=>array('_of'=>'json')));	
		$json = $ret->json();
		$this->assertEquals('hapn.u_notfound',$json['err']);
		$ret = $this->fetch('/HapN/_after',array('get'=>array('_of'=>'json')));	
		$json = $ret->json();
		$this->assertEquals('hapn.u_notfound',$json['err']);
	}

	function testRedirectHeader()
	{
		$ret = $this->fetch('/HapN/testRedirectHeader',array());	
		$this->assertEquals('bbb',$ret->headers['aaa']);
		$this->assertEquals('myname',$ret->cookies['mykey']);

	}

	function testInputCheck()
	{
		$ret = $this->fetch('/HapN/testInputCheck',array('get'=>array('_of'=>'json','key1'=>'787634561','key2'=>'sdfsd')));	
		$json = $ret->json();
		$this->assertEquals('hapn.u_input', $json['err']);
		$this->assertTrue(isset($json['data']['key2']));
	}

	function testSkipFatal()
	{
		$ret = $this->fetch('/HapN/testSkipFatal',array('get'=>array('_of'=>'json')));	
		$json = $ret->json();
		$this->assertEquals('hapn.ok',$json['err']);
	}

	function testNocacheAndEnd()
	{
		$ret = $this->fetch('/HapN/testNocacheAndEnd',array('get'=>array('_of'=>'json')));	
		$json = $ret->json();
		$this->assertEquals('hapn.ok',$json['err']);
		$header = $ret->headers;
		$this->assertTrue(isset($header['Expires']));
		$this->assertTrue(isset($header['Cache-Control']));
		$this->assertTrue(isset($header['Pragma']));
	}

	function testMustPost()
	{
		$ret = $this->fetch('/HapN/_mustpost',array('get'=>array('_of'=>'json')));	
		$json = $ret->json();
		$this->assertEquals('hapn.u_notfound',$json['err']);

		$ret = $this->fetch('/HapN/_mustpost',array('get'=>array('_of'=>'json','key'=>'v'),'post'=>array('key'=>'value')));	
		$json = $ret->json();
		$this->assertEquals('hapn.ok',$json['err']);
	}

	function testLogin()
	{
		$ret = $this->fetch('/HapN/testLogin',array());	
		$this->assertTrue(strpos($ret->redirect,'%2FHapN%2FtestLogin')>0);
	}

}




/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */
?>
